#include"CyclicBarrier .h"
#include<iostream>
#include<vector>
#include<functional>
using namespace std;
void Complete() {
	std::cout << "Complete" << std::endl;
}
using Func = std::function<void()>;
Func func = std::bind(Complete);
CyclicBarrier<Func> barrier(3, func);
std::mutex mx;

void func1() {
	{
		auto index=barrier.await();
		std::unique_lock<std::mutex>lock(mx);
		std::cout << "func1: " << index << std::endl;
		barrier.reset();
	}
}

void func2() {
	 {
		auto index = barrier.await();
		std::unique_lock<std::mutex>lock(mx);
		std::cout << "func2: " << index << std::endl;
	}
}

void func3() {
	 {
		auto index = barrier.await();
		std::unique_lock<std::mutex>lock(mx);
		std::cout << "func3: " << index << std::endl;
	}
}

void func4() {
	{
		auto index = barrier.await();
		std::unique_lock<std::mutex>lock(mx);
		std::cout << "func4: " << index << std::endl;
	}
}

int main() {
	vector<thread>vec;
	vec.push_back(thread(func4));
	vec.push_back(thread(func1));
	vec.push_back(thread(func2));
	vec.push_back(thread(func3));
	for (int i = 0; i < vec.size(); ++i)
		vec[i].join();
}